package mumu.android.crypt;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import mumu.android.R;
import mumu.android.lib.localstorage.NewsEn;
import mumu.android.lib.tool.DESTool2;
import mumu.android.lib.tool.JsonHp;
import mumu.android.lib.tool.MLog;
import mumu.android.lib.tool.Tools;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;

public class json extends DialogFragment {

	static json instance;

	public static json getInstance() {
		if (instance == null) {
			instance = new json();
		}
		return instance;
	}

	@Override
	public void dismiss() {
		super.dismiss();
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
	}

	Dialog dialog;
	TextView txt;

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		if (dialog == null) {
			dialog = new Dialog(getActivity(), R.style.dialog);
			LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
			View view = layoutInflater.inflate(R.layout.dialog_listview, null);
			view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
			dialog.setContentView(R.layout.dialog_listview);
			dialog.setCanceledOnTouchOutside(true);
		} else {
			txt.setText("Wuhan");
		}

		String plaintext = "[{\"newsid\":0},{\"newsid\":1}]";
		List<NewsEn> list = new ArrayList<NewsEn>();
		TypeToken<List<NewsEn>> token= new TypeToken<List<NewsEn>>(){};
		Gson gson = new Gson();
		list = gson.fromJson(plaintext, token.getType());
		String ciphertext = "";
		try {
			ciphertext = DESTool2.encryptDES(plaintext, "key!12@3");

		} catch (Exception e) {
			e.printStackTrace();
		}
		return dialog;
		// return super.onCreateDialog(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		MLog.d("dds", "onCreateView");
		return super.onCreateView(inflater, container, savedInstanceState);
	}

}
